package com.work.ygj.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.work.ygj.common.model.Response;
import com.work.ygj.common.model.page.PageResult;
import com.work.ygj.entity.GcStation;
import com.work.ygj.pojo.dto.GcStationDto;
import com.work.ygj.pojo.vo.GcStationVo;
import com.work.ygj.service.GcStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  垃圾站管理(管理员)(用户只能看列表)
 *
 * @author ygj
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/gcStation")
@ResponseBody
public class GcStationController extends BaseController {

    @Autowired
    private GcStationService gcStationService;
    /**
     * 垃圾站列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<GcStationVo>> selectList(@RequestBody GcStationDto dto){
        return Response.success(getDataTable(gcStationService.selectList(dto)));
    }

    /**
     * 新增垃圾站信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody GcStation req) {
        gcStationService.save(req);
        return Response.success();
    }


    /**
     * 修改垃圾站信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody GcStation req) {
        UpdateWrapper<GcStation> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        gcStationService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除垃圾站记录
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody GcStation req) {
        GcStation entity = new GcStation();
        entity.setId(req.getId());
        entity.setDeleted("1");
        gcStationService.updateById(entity);
        return Response.success();
    }

    /**
     * 垃圾站信息详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<GcStation> detail(@RequestBody GcStation req) {
        GcStation entity = gcStationService.getById(req.getId());
        return Response.success(entity);
    }
}

